﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LTHD_Web.WS;

namespace LTHD_Web
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void LoginButton_Click(object sender, EventArgs e)
        {
            string _username = LoginUser.UserName.Trim();
            string _password = LoginUser.Password.Trim();
            if (_username == "")
            {
                lbThongBao.Text = "Username is empty";
            }
            else 
                if (_password == "")
            {
                lbThongBao.Text = "Password is empty";
            }
            else
            {
                Service1SoapClient ws = new Service1SoapClient();
                _password = MaHoa.Encrypt(_password, true);
                TaiKhoanDTO taiKhoan = ws.logIn(_username, _password);
                if (taiKhoan != null)
                {
                    Session.Add("taiKhoan", taiKhoan);
                    Response.Cookies["userName"].Value = taiKhoan.TenTaiKhoan;
                    Response.Cookies["userName"].Expires = DateTime.Now.AddMinutes(20);
                    HttpCookie aCookie = new HttpCookie("lastVisit");
                    aCookie.Value = DateTime.Now.ToString();
                    aCookie.Expires = DateTime.Now.AddDays(1);
                    Response.Cookies.Add(aCookie);
                    //Response.Redirect("Default.aspx");

                    
                }
                else
                {
                    lbThongBao.Text = "The login email and password do not match";
                }
            }
        }
    }
}